package cn.javadog.smartbreeding.record.controller;

import java.util.List;
import java.util.Map;

import cn.javadog.smartbreeding.core.dto.PageDTO;
import cn.javadog.smartbreeding.core.dto.TemperatureRecordDTO;
import cn.javadog.smartbreeding.core.service.TemperatureRecordService;
import cn.javadog.smartbreeding.core.config.util.Ret;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 余勇
 */
@Api(tags = "温度记录")
@RestController
@RequestMapping("temperature/records")
public class TemperatureRecordController {

	@Autowired
	private TemperatureRecordService temperatureRecordService;

	@ApiOperation("温度录入")
	@PostMapping
	public Ret save(@RequestBody TemperatureRecordDTO dto) {
		return Ret.ok(temperatureRecordService.save(dto));
	}

	@ApiOperation("温度列表")
	@GetMapping
	public Ret list(PageDTO dto) {
		return Ret.ok(temperatureRecordService.list(dto));
	}


	@Autowired
	private JdbcTemplate jdbcTemplate;

	@ApiOperation("测试jdbcTemplate")
	@GetMapping("jdbc")
	public Ret jdbc(){
		List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from temperature_record");
		return Ret.ok(maps);
	}

}
